﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using OpenExpressApp.Types;
using System.Windows.Media;
using OpenExpressApp.MetaModel;
using System.Windows;


namespace OpenExpressApp.MetaAttribute
{

    [AttributeUsage(AttributeTargets.Class)]
    public class BusinessObjectAttribute : Attribute
    {
        public BusinessObjectAttribute(string id)
        {
            this.Id = id;
            Direction = Direction.Vertical;
            ModuleType = ModuleType.Bill;
            InDataPermission = false;
        }

        public bool InDataPermission { get; set; }

        /// <summary>
        /// 显示的列表的高度
        /// </summary>
        public int Height { get; set; }
        public string Id { get; set; }
        public Direction Direction { get; set; }
        public ModuleType ModuleType { get; set; }
        //默认分组
        public string PropertyGroup { get; set; }
    }

    [AttributeUsage(AttributeTargets.Class)]
    public class BackColorAttribute : Attribute
    {
        public BackColorAttribute(byte r, byte g, byte b)
        {
            Color = Color.FromRgb(r, g, b);
        }
        public Color Color { get; private set; }
    }

    [AttributeUsage(AttributeTargets.Class, Inherited = false)]
    public class DefaultObjectAttribute : BusinessObjectAttribute
    {
        public DefaultObjectAttribute(string id)
            : base(id)
        {
            ShowInModule = true;
            DefaultOpen = false;
        }
        /// <summary>
        /// 顺序号,控制显示在模块列表中的顺序
        /// </summary>
        public int Index { get; set; }
        /// <summary>
        /// 是否显示在模块列表中，缺省显示
        /// </summary>
        public bool ShowInModule { get; set; }
        public string Catalog { get; set; }
        public bool DefaultOpen { get; set; }
    }

    [AttributeUsage(AttributeTargets.Property, Inherited = false)]
    public class EntityPropertyAttribute : Attribute
    {
        /// <summary>
        /// 用于排序属性
        /// </summary>
        private double _orderNo;

        public EntityPropertyAttribute() { }

        public EntityPropertyAttribute(double orderNo)
        {
            this._orderNo = orderNo;
        }

        /// <summary>
        /// 用于排序属性
        /// </summary>
        public double OrderNo
        {
            get
            {
                return this._orderNo;
            }
            set
            {
                this._orderNo = value;
            }
        }

        /// <summary>
        /// 此属性用到格式代当前的属性
        /// </summary>
        private string _stringFormat;

        /// <summary>
        /// 此属性用到格式代当前的属性
        /// </summary>
        public string StringFormat
        {
            get
            {
                return this._stringFormat;
            }
            set
            {
                this._stringFormat = value;
            }
        }
    }

    /// <summary>
    /// 标记某属性是否只读
    /// </summary>
    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Class, Inherited = false)]
    public class IsReadOnlyAttribute : Attribute
    {
        /// <summary>
        /// 如果此属性不是null或empty，则通过对象的属性获取只读值。
        /// </summary>
        public string PropertyName { get; set; }
    }

    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Class, Inherited = false)]
    public class IsVisibleAttribute : Attribute
    {
        //通过绑定获取对象的只读值
        public string PropertyName { get; set; }
    }


    /// <summary>
    /// 选择新增记录时根据此方法进行判断是否可以添加进父窗口
    /// </summary>
    [AttributeUsage(AttributeTargets.Method, Inherited = false)]
    public class CanAddMethodAttribute : Attribute { }

    /// <summary>
    /// 考虑数据权限，目前只是标识
    /// </summary>
    [AttributeUsage(AttributeTargets.Method, Inherited = false)]
    public class DataPermissionAttribute : Attribute { }

    /// <summary>
    /// 在命令类上存在调用OpenApplication.CreateListForm弹出二级窗口，这时为了能够设定功能权限，需要加上此元信息
    /// </summary>
    [AttributeUsage(AttributeTargets.Class, Inherited = false)]
    public class InPermissionAttribute : Attribute
    {

        public InPermissionAttribute(Type child, Type owner)
        {
            this.Child = child;
            this.Owner = owner;
        }

        public Type Child { get; set; }
        public Type Owner { get; set; }
    }


    [AttributeUsage(AttributeTargets.Property, Inherited = false)]
    public class ShowInListAttribute : Attribute
    {
        public ShowInListAttribute()
        {
            this.MinWidth = 0;
        }

        public double MinWidth { get; set; }
    }

    [AttributeUsage(AttributeTargets.Property, Inherited = false)]
    public class ShowInLookupAttribute : Attribute { }

    /// <summary>
    /// 某些标记了IsTitle的属性，如果不想显示在Lookup中，则标记上这个。
    /// </summary>
    [AttributeUsage(AttributeTargets.Property, Inherited = false)]
    public class NotShowInLookupAttribute : Attribute { }

    /// <summary>
    /// ShowInList的ShowInDetail为True
    /// </summary>
    [AttributeUsage(AttributeTargets.Property, Inherited = false)]
    public class ShowInDetailAttribute : Attribute { }

    [AttributeUsage(AttributeTargets.Property, Inherited = false)]
    public class RequiredAttribute : Attribute { }

    [AttributeUsage(AttributeTargets.Property, Inherited = false)]
    public class IsTitleAttribute : Attribute { }

    [AttributeUsage(AttributeTargets.Property, Inherited = false)]
    public class EditorAttribute : Attribute
    {
        public EditorAttribute(string name)
        {
            this.Name = name;
        }

        public string Name { get; private set; }
    }

    public class LabelAttribute : Attribute
    {
        public LabelAttribute(string label)
        {
            Label = label;
        }

        public string Label { get; private set; }
    }

    /// <summary>
    /// 关联属性会为对象生成一个明细信息
    /// </summary>
    [AttributeUsage(AttributeTargets.Property)]
    public class AssociationAttribute : Attribute
    {
        public AssociationAttribute()
        {
            this.IsRecur = true;
            this.CreateToolbar = true;
            this.AssociationOperateType = AssociationOperateType.Self;
            this.IsVisible = true;
        }

        /// <summary>
        /// 和主表显示成树形结构。默认显示为Tab页签
        /// </summary>
        public bool ShowInTree { get; set; }
        /// <summary>
        /// 表示这个子属性是否需要显示在界面上。
        /// </summary>
        public bool IsVisible { get; set; }
        /// <summary>
        /// 是否递归生成它的子对象
        /// </summary>
        public bool IsRecur { get; set; }
        /// <summary>
        /// 是否生成工具条
        /// </summary>
        public bool CreateToolbar { get; set; }
        /// <summary>
        /// 是否采用选择操作对象模式
        /// </summary>
        public AssociationOperateType AssociationOperateType { get; set; }
    }



    /// <summary>
    /// 子表显示类型
    /// </summary>
    [AttributeUsage(AttributeTargets.Property)]
    public class ChildShowTypeAttribute : Attribute
    {
        public ChildShowTypeAttribute()
        {
            ChildShowType = ChildObjectShowType.Tab;
            PopName = string.Empty;
            this.Visibility = Visibility.Hidden;
        }
        /// <summary>
        /// 子表显示类型
        /// </summary>
        public ChildObjectShowType ChildShowType { get; set; }
        public string PopName { get; set; }
        public Visibility Visibility { get; set; }
    }
    /// <summary>
    /// 字段关联属性,新增时通过选择操作
    /// </summary>
    [AttributeUsage(AttributeTargets.Property, Inherited = false)]
    public class LookupAttribute : Attribute
    {
        public LookupAttribute()
        {
            this.LookupPropertyName = string.Empty;
            this.IsParent = false;
        }
        public LookupAttribute(string lookupPropertyName)
        {
            this.LookupPropertyName = lookupPropertyName;
            this.UseSelectAddCommand = false;
        }

        /// <summary>
        /// 是否parent对象外键字段
        /// </summary>
        public bool IsParent { get; set; }

        /// <summary>
        /// 是否1：1子对象对应外键字段
        /// </summary>
        public bool IsChild { get; set; }

        /// <summary>
        /// 是否使用选择按钮来支持添加功能
        /// </summary>
        public bool UseSelectAddCommand { get; set; }

        /// <summary>
        /// 定义在对象自身上的属性的名字，当下拉选择时，会把选择的对象赋值给这个属性
        /// </summary>
        public string LookupPropertyName { get; set; }
        /// <summary>
        /// 一个路径表达式。
        /// 下拉选择时，从当前选中的对象找到值，赋值给LookupPropertyName指定的属性
        /// </summary>
        public string SelectedValuePath { get; set; }
        /// <summary>
        /// 查询时，数据来源的属性。在这个属性里面查找值。
        /// 级联属性过滤串,格式如:属性.子属性.子子属性...
        /// 
        /// 如果未设置这个值，则会调用数据层方法查询
        /// </summary>
        public string DataSourceProperty { get; set; }
        /// <summary>
        /// Lookup对象类型
        /// </summary>
        public Type LookupType { get; set; }
        /// <summary>
        /// 如果Lookup是树形结构，设置或获取RootPId的属性名，可以只显示部分树
        /// </summary>
        public string RootPIdProperty { get; set; }
    }


    [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
    public class EnumAttr : Attribute
    {
        public string Label { get; set; }
        public EnumAttr(string label)
        {
            this.Label = label;
        }
    }
}
